// components/Dialog/dialog.js
var WxParse = require('../wxParse/wxParse.js');
var common = require('../../common.js');
var businessLogic = require('../../NetWork/Model/MainbusinessLogic.js')

Component({
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  /**
   * 组件的属性列表
   * 用于组件自定义设置
   */
  properties: {

  },
  /**
   * 私有数据,组件的初始数据
   * 可用于模版渲染
   */
  data: {
    // 弹窗显示控制
    isShow: false,
    topic: "",//整体的题目
    datiNum: "",
    xiaotiNum: "",
    titype: "",//这道题的类型
    mydaan: "",
    queren: '未确认',
    tijiao: '未提交',
    remarktype: "",
    score: "",
    pinjia: "",
    scored: "请输入得分",//这道题的得分
    examid: "",
    rubric: "",
    defen: '',
    pinjia: '',
    analysis:'',
    point:''
  },
  /**
   * 组件的方法列表
   * 更新属性和数据的方法与更新页面数据的方法类似
   */
  methods: {
    //==============================###题目的解析
    //题目的数据中心
    timu(dati, xiaoti, topic, remarktype, examid) {
       // 大题,小题,题目,题目类型,考试id
      
      // remarktype的解释
      // 0 == 可以修改选择的
      // 1 == 可以增加、修改评语，得分
      // 2 == 不可以修改卷子
      // 3 == 不可以修改卷子而且有评语和得分
      // 4 == 不可以修改卷子,可以看到答案
      this.setData({
        remarktype: remarktype//获取考试类型
      })
      let rubric = topic[dati].qt[xiaoti];//获取那道题的内容
      var article = rubric.subcontent;//把题干通过富文本显示器挂上去
      console.log(rubric)
      var that = this;
      WxParse.wxParse('article', 'html', article, that, 20);
      // console.log(rubric)

      this.setData({
        topic: topic,//整个题目上传数据中心
        datiNum: dati,//大题
        xiaotiNum: xiaoti,//小题
        rubric: rubric,//获取那道题的内容
        analysis: rubric.analysis//题目的解析
      })
      // console.log(rubric);
      let sureflag = "";
      if (rubric.typecode == "单选题" || rubric.typecode == "多选题") {
        sureflag = 1;
        this.setData({
          titype: "选择题",
          scored: rubric.score//这道题的得分
        })
        this.ChoiceQuestion = this.selectComponent("#ChoiceQuestion");
        this.ChoiceQuestion.tiantimu(rubric, this.data.remarktype);

      } else if (rubric.typecode == "综合题") {
        sureflag = 0;
        
        this.setData({
          titype: "综合题",
          scored: rubric.score//这道题的得分
        })
        this.Comprehensive = this.selectComponent("#Comprehensive");
        this.Comprehensive.tiantimu(rubric, this.data.remarktype, this.data.examid);
      } else {
        sureflag = 1;
        
        this.setData({
          titype: "填空题",
          scored: rubric.score//这道题的得分
        })
        this.GapFilling = this.selectComponent("#GapFilling");
        this.GapFilling.tiantimu(rubric, this.data.remarktype);

      }
      console.log("将这道题的id返回给上一个页面", rubric.id);
      // return rubric.id;
      let timu =[];

      timu[0] = rubric.id;
      timu[1] = sureflag;

      return timu;
       
    },

    //==================未知函数
    examid(examid) {
      this.setData({
        examid: examid
      })
    },
    //==================未知函数

    //====================================按下确定按钮之后 
    //1.确认按钮 其他的
    sure: function () {
      this.mydan();//获取答案

      if (this.data.mydata == ''||this.data.mydata == '请选择答案' || this.data.mydata == undefined) {
        common.showToast("请选择答案", "none");
      } else {
        this.setData({
          queren: '已确认',
          color: true,
        })
        var sureAnswer = [];
        sureAnswer["mydata"] = this.data.mydata;
        sureAnswer["rubric"] = this.data.rubric;
        return sureAnswer;
      }

    },
    surezonghe:function(){
      let mydaan = this.Comprehensive.sure();
      this.Comprehensive.xiayiti();
      return mydaan;
    },
    //2.通过组件获取答案
    mydan() {
      var mydaan = "";
      this.ChoiceQuestion = this.selectComponent("#ChoiceQuestion");
      this.GapFilling = this.selectComponent("#GapFilling");
      if (this.data.titype == "填空题") {
        mydaan = this.GapFilling.mydaan();
        if (this.GapFilling.mydaan() == "" || this.GapFilling.mydaan() == null) {
          mydaan = "";
        }
      } else {
        mydaan = this.ChoiceQuestion.mydaan();
      }
      this.setData({
        mydata: mydaan
      })
    },
    dingzhentimu(topic, remarktype, testid) {
      let rubric = topic
      this.setData({
        rubric: topic,
        remarktype: remarktype,
        testid: testid,
      })
      console.log(this.data.remarktype);
      // let rubric = topic[dati].qt[xiaoti];//获取那道题
      var article = topic.subcontent;//把题干通过富文本显示器挂上去
    
      var that = this;
      WxParse.wxParse('article', 'html', article, that, 20);
      console.log(rubric)
      if (rubric.typecode == "单选题" || rubric.typecode == "多选题") {
        this.setData({
          titype: "选择题",
          scored: "",
        })

        this.ChoiceQuestion = this.selectComponent("#ChoiceQuestion");
        this.ChoiceQuestion.tiantimu(rubric, this.data.remarktype);

      } else if (rubric.typecode == "综合题") {
        this.setData({
          titype: "综合题",
          scored: ""
        })
        this.Comprehensive = this.selectComponent("#Comprehensive");
        this.Comprehensive.tiantimu(rubric, this.data.remarktype, this.data.examid);
      } else {
        this.setData({
          titype: "填空题",
          scored: ""
        })
        this.GapFilling = this.selectComponent("#GapFilling");
        this.GapFilling.tiantimu(rubric, this.data.remarktype);

      }
      console.log("testid", rubric.id);
      return rubric.id;
    },
    //本人做的一些答案返回的传递
    Newstext(res) {
      console.log("试题的答案", res);
      if (res.say == "" || res.say == undefined){
        this.setData({
          point: res.point,
          pinjia: "",
          defen: res.score,
        })
      }else{
        this.setData({
          point: res.point,
          pinjia: res.say 
        })
      }
     
      if (this.data.titype == "选择题") {
        this.ChoiceQuestion.zxtext(res.newstext);

      } else if (this.data.titype == "综合题") {
        // this.Comprehensive.chuli(this.data.examid);

      } else {
        // 填空题
        if (res.newstext=="undefined"){
         
        }else{
          this.GapFilling.tktext(res.newstext);
        }

      }

    }, 
    //================得分的方法
    defenInput(e) {
      this.setData({
        point: e.detail.value
      })
      console.log(e.detail.value);

    },
    //评价的方法
    pingyuInput(e) {
      this.setData({
        pinjia: e.detail.value
      })
      console.log(e.detail.value);
    },
    //获取得分
    getdepy(){
      var a=[];
      a[0] = this.data.defen;
      a[1] = this.data.pinjia;
      a[2] = this.data.point;
      return a;
      
    },
    /*
    * 内部私有方法建议以下划线开头
    * triggerEvent 用于触发事件
    */
    _cancelEvent() {
      //触发取消回调
      this.triggerEvent("cancelEvent")
    },
    _confirmEvent() {
      //触发成功回调
     
    }
  }
})